import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n=scanner.nextInt();
        int x=scanner.nextInt();
        int[] nums=new int[n];
        for(int i=0;i<n;i++){
            nums[i]=scanner.nextInt();
        }
        int sum=0;
        for(int a:nums){
            sum+=a;
        }
        int det=sum-x;
        if(det<0) {
            System.out.println(-1);
            return;
        }
        int left=0,right=0;
        int sum1=0;
        int length=-1;
        while (right<n){
            sum1+=nums[right++];
            while (sum1>det){
                sum1-=nums[left++];
            }
            if(sum1==det) {
                length=right-left>=length?right-left:length;
            }
        }
        if(length>=0)
        System.out.println(nums.length - length);
        else System.out.println(-1);
    }
    public static void main3(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n=scanner.nextInt();
        int[] fruits=new int[n];
       HashMap<Integer,Integer> hashMap=new HashMap<>();
        for(int i=0;i<n;i++){
            fruits[i]=scanner.nextInt();
        }
        int lift=0,right=0;
        int sum=-1;
        while (right<n){
            if(!hashMap.containsKey(fruits[right])) hashMap.put(fruits[right],1);
            else hashMap.put(fruits[right],hashMap.get(fruits[right])+1);
            right++;
            while (hashMap.size()>2){
                hashMap.put(fruits[lift],hashMap.get(fruits[lift])-1);
                if(hashMap.get(fruits[lift])==0) hashMap.remove(fruits[lift]);
                lift++;
            }
            sum=(right-lift)>=sum?(right-lift):sum;
        }
        System.out.println(sum);
    }
    public static void main2(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        HashMap<Integer,Integer> hashMap=new HashMap<>();
        for(int i=0;i<n;i++){
            if(!hashMap.containsKey(ints[i])){
                hashMap.put(ints[i],1);
            }
            else {
                hashMap.put(ints[i], hashMap.get(ints[i])+1);
            }
        }
        System.out.println(hashMap.get(ints[1]));
        //System.out.println(Arrays.toString(hashMap.values().toArray()));
    }
    public static long func(long N,long K) {
        if(N==0) return 0;
        else {
            int n=0;
            while (!(Math.pow(2,n)<=N&&Math.pow(2,n+1)-1>=N)){
                n++;
            }
            return func(N-(long) Math.pow(2,n),K)+(long)Math.pow(K,n);
        }
    }
    public static void main1(String[] args) {
        Scanner scanner=new Scanner(System.in);
        long k=scanner.nextInt();
        long N=scanner.nextInt();
        System.out.println(func(N,k));
    }
}
